package examenJunio2013DAM;

import java.util.Scanner;
/*
153=1^3+5^3+3^3
370=3^3+7^3+0^3
 371=3^3+7^3+1^3
407=4^3+0^3+7^3
*/
public class NumArmstrong {

	public  boolean esNumValido(String n) {
		try {
			long d = Long.parseLong(n);
		} catch (NumberFormatException nfe) {
			return false;
		}
		return true;
	}

	public  double potencia(long base, long exp) {
		if (exp == 0)
			return 1;
		else
			return base*potencia(base, exp - 1);

	}

	public  boolean esArmstrong(long a) {

		long n = a;
		long total = 0;
		long exp = Long.toString(n).length();
		
		for(int i=(int) exp; i>0;--i)	
		{			
			total+=potencia(n%10,exp);				
			n = n/10;
		}
		
		return (a==total);
		
	}

	public  void test(long a) {
		long n = a;
		long total = 0;
		long exp = Long.toString(n).length();
		
		for(int i=(int) exp; i>0;--i)	
		{
			System.out.print(n%10+"^"+exp);
			total+=potencia(n%10,exp);
			if (i>1) System.out.print(" + ");		
			n = n/10;
			
		}
		System.out.println("= "+total);
	}

	 
	
	

}